const express = require("express");
const app = new express();
const cors = require("cors");
const bodyParser=require('body-parser')

//引入路由
const loginRouter = require('./src/router/user/login')
const addressRouter = require('./src/router/user/address')
const productRouter=require('./src/router/mall/product')
const cartRouter = require('./src/router/mall/shoppingcart')
const orderRouter = require('./src/router/mall/order')
const homeRouter=require('./src/router/mall/home')
app.use(cors());

// 中间件bodyparser的配置固定步骤
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

//路由
app.use('/user', loginRouter)
app.use('/user',addressRouter)

app.use('/mall', productRouter)
app.use('/mall', cartRouter)
app.use('/mall', orderRouter)
app.use('/mall', homeRouter)

const server = app.listen(4000, "localhost", (req, res) => {
    const host = server.address().address;
    const port = server.address().port;
    console.log(`The server running on http://${host}:${port}`);
});
